# -*- coding: utf-8 -*-
"""The application's Globals object"""

from beaker.cache import CacheManager
from beaker.util import parse_cache_config_options
from craneserver.lib.command_queue import (CommandQueue,
                                           parse_command_queue_options)
from craneserver.lib.mongo import (make_gridfs_connection,
                                   make_mongodb_connection,
                                   parse_gridfs_options,
                                   parse_mongodb_options)


class Globals(object):
    """Globals acts as a container for objects available throughout the
    life of the application

    """

    def __init__(self, config):
        """One instance of Globals is created during application
        initialization and is available during requests via the
        'app_globals' variable

        """
        #print config

        self.cache = CacheManager(**parse_cache_config_options(config))
        self.command_queue = CommandQueue(**parse_command_queue_options(config))
        self.mongodb = make_mongodb_connection(**parse_mongodb_options(config))
        self.gridfs = make_gridfs_connection(conn=self.mongodb,
                                             **parse_gridfs_options(config))
